<?php
class gd_draw{
	
static function line($image, $data){
	$color = imarty_color($image, $data['color'], (int)$data['alpha']);
	imageline($image, $data['x1'],$data['y1'],$data['x2'],$data['y2'],$color);
}

static function pixel($image, $data){
	$color = imarty_color($image, $data['color'], (int)$data['alpha']);
	imagesetpixel($image, $data['x'],$data['y'],$color);
}

static function ellipse($image, $data){
	$color = imarty_color($image, $data['color'], (int)$data['alpha']);
	if($data['fill'] == 'on'){
		imagefilledellipse($image, $data['x'], $data['y'], $data['w'], $data['h'], $color);
	}else{
		imageellipse($image, $data['x'], $data['y'], $data['w'], $data['h'], $color);
	}
}

static function circle($image, $data){
	$color = imarty_color($image, $data['color'], (int)$data['alpha']);
	if(isset($data['r'])){
		$data['radius'] = (int)$data['r'];
	}
	
	if($data['fill'] == 'on'){
		imagefilledellipse($image, $data['x'], $data['y'], $data['radius'], $data['radius'], $color);
	}else{
		imageellipse($image, $data['x'], $data['y'],$data['radius'], $data['radius'], $color);
	}
}


static function rectangle($image, $data){
	$color = imarty_color($image, $data['color'], (int)$data['alpha']);
	if($data['fill']){
		if(isset($data['x1'])){
			imagefilledrectangle($image, $data['x1'], $data['y1'], $data['x2'], $data['y2'], $color);
		}else{
			imagefilledrectangle($image, $data['x'], $data['y'], $data['x'] + $data['w'], $data['y'] + $data['h'], $color);
		}
	}else{
		if(isset($data['x1'])){
			imagerectangle($image, $data['x1'], $data['y1'], $data['x2'], $data['y2'], $color);
		}else{
			imagerectangle($image, $data['x'], $data['y'], $data['x'] + $data['w'], $data['y'] + $data['h'], $color);
		}
	}
}

static function polygon($image, $data){
	$color = imarty_color($image, $data['color'], (int)$data['alpha']);
	$num_points = count($data->point);
	foreach($data->point as $point){
		$points[] = $point['x'];
		$points[] = $point['y'];
	}
	if($data['fill']){
		imagefilledpolygon($image, $points, $num_points, $color);
	}else{
		imagepolygon($image, $points, $num_points, $color);
	}
}

static function fill($image, $data){
	$color = imarty_color($image, $data['color'], (int)$data['alpha']);
	if(isset($data['border_color'])){
		$border_color = imarty_color($image, $data['border_color'], (int)$data['border_alpha']);
		imagefilltoborder($image, $data['x'], $data['y'], $border_color, $color);
	}else{
		imagefill($image, $data['x'], $data['y'], $color);
	}
}
}
?>